import { observable, action, autorun,toJS } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import { ListStore } from './listStore';
import {WeaTools,WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import * as Apis from '../apis/approval';
import * as Apis_common from "../apis/index"
import * as Apis_task from '../apis/task';
import {ExchangeStore } from "./exchangeStore"
import {Modal} from 'antd';
const confirm = Modal.confirm;

class ApprovalStore  extends ListStore{	
	title = getLabel(16410,"审批任务");

	@observable rightMenu =[];
	conditiontype = {conditiontype:"approval"};
	
	@observable verified = false;
	@observable hasRight = false; //权限

	@observable exchangeStore = new ExchangeStore();

	@observable logVisible =false;   //任务修改记录
	@observable logTableStore = new TableStore();
	treeType = {};

	@action
    initDatas=(params = {})=> {
		let newParams = {...this.conditiontype,...params};
		this.title = this.title;
		Apis_common.getTaskCondition(newParams).then(data=>{
			this.condition = data.condition;
			//根据高级搜索条件初始化form
			this.form && !this.form.isFormInit && this.form.initFormFields(data.condition);
		});
    }

    doSearch=(params={})=>{
		this.loading = true;
		 //获取表单的参数值
		const searchParamsAd = this.form.getFormParams();
		const newParams = {  ...searchParamsAd,...this.treeType, ...params };
		if(params.prjtype){
            this.treeType = {prjtype:params.prjtype}
         }
        Apis.getApprovalList(newParams).then(data=>{
			this.tableStore.getDatas(data.sessionkey,  params.current || 1);
			this.dataKey = data.sessionkey;
			this.rightMenu = data.rightMenus;
            this.loading = false;
        })
	}
	onShowColumn=()=>{
		this.tableStore.setColSetVisible(true);
		this.tableStore.tableColSet(true)
	}

	doTaskApprovalOpt=(params={})=>{
		let _this = this;
		let method = params.method;
		let confirm_msg = "";
		if(method=='refuse'){
			confirm_msg = getLabel(83886,"您确认要退回选中的记录吗？");
		}else{
			confirm_msg = getLabel(83884,"您确认要批准选中的记录吗？");
		}
		Modal.confirm({
			title: getLabel(15172,"系统提示"),
			content: confirm_msg,
			onOk() {
				Apis.doTaskApprovalOpt(params).then(data=>{
					_this.doSearch();
					//刷新右侧菜单
					loadLeftMenuCount();
				})
			},
			onCancel() { },
		})
	}

	
	clearStatus=()=>{
        this.showSearchAd = false;
		this.clearFormFields();
		this.resetForm();
        this.condition = [];
        this.resetTable(true);
	}
	
	//修改记录
	viewModifyLog = (id)=>{
		this.logVisible = true;
		this.logTableStore = new TableStore();
		Apis_task.taskModifyList({taskid:id}).then(data=>{
			this.logTableStore.getDatas(data.sessionkey,1);
		})
	}

}

const prjApprovalStore = new ApprovalStore();
export default prjApprovalStore;